package com.ccctop.cloud.handler;

import com.ccctop.cloud.service.api.TFundRequestService;
import com.ccctop.crowd.entity.po.ProjectPO;
import com.ccctop.crowd.entity.po.TFundRequest;
import com.ccctop.crowd.util.ResultEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * (TFundRequest)表控制层
 *
 * @author makejava
 * @since 2022-02-20 17:44:11
 */
@RestController
public class TFundRequestController {
    /**
     * 服务对象
     */
    @Resource
    private TFundRequestService tFundRequestService;

    @RequestMapping("/fund/info")
    ResultEntity<List<TFundRequest>> fundInfo(@RequestParam("userId") Integer userId){
        try{
            return ResultEntity.successWithData(tFundRequestService.fundInfo(userId));
        }catch (Exception e){
            e.printStackTrace();
            return ResultEntity.failed(e.getMessage());
        }
    }

    @RequestMapping("/fund/agree")
    ResultEntity<String> fundAgree(@RequestParam("itemId") Integer itemId){
        try{
            tFundRequestService.fundAgree(itemId);
            return ResultEntity.successWithoutData();
        }catch (Exception e){
            return ResultEntity.failed(e.getMessage());
        }
    }

    @RequestMapping("/fund/refuse")
    ResultEntity<String> fundRefuse(@RequestParam("itemId") Integer itemId){
        try{
            tFundRequestService.fundRefuse(itemId);
            return ResultEntity.successWithoutData();
        }catch (Exception e){
            return ResultEntity.failed(e.getMessage());
        }
    }

    @RequestMapping("/fund/save")
    ResultEntity<String> saveRequests(@RequestBody List<TFundRequest> requests){
        try{
            tFundRequestService.saveRequests(requests);
            return ResultEntity.successWithoutData();
        }catch (Exception e){
            return ResultEntity.failed(e.getMessage());
        }
    }

    @RequestMapping("/fund/query")
    ResultEntity<TFundRequest> fundQuery(@RequestParam("itemId") Integer itemId){
        try{
            return ResultEntity.successWithData(tFundRequestService.fundQuery(itemId));
        }catch (Exception e){
            return ResultEntity.failed(e.getMessage());
        }
    }

}